package com.hongyuan.venue.ui.person.view_mode;

import android.app.Application;
import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import com.hongyuan.mvvmhabitx.binding.command.BindingAction;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.venue.base.CustomViewModel;
import com.hongyuan.venue.data.Constants;
import com.hongyuan.venue.data.MyRepository;
import com.hongyuan.venue.ui.person.activity.EditInformationActivity;
import com.hongyuan.venue.ui.person.activity.MyCouponActivity;
import com.hongyuan.venue.ui.person.activity.MyOrdersActivity;
import com.hongyuan.venue.ui.person.activity.SettingActivity;
import com.hongyuan.venue.ui.person.activity.TrainOrdersActivity;
import com.hongyuan.venue.ui.person.beans.KeFuBean;
import com.hongyuan.venue.ui.person.beans.PersonBean;

public class PersonViewModel extends CustomViewModel<MyRepository> {

    public ObservableField<PersonBean.InfoBean> entity = new ObservableField<>();

    public ObservableField<KeFuBean> callKfTel = new ObservableField<>();

    public PersonViewModel(@NonNull Application application, MyRepository model) {
        super(application, model);
    }

    //个人主页
    public BindingCommand goInfo = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(EditInformationActivity.class,null);
        }
    });

    //我的订单
    public BindingCommand goMyOrders = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(MyOrdersActivity.class);
        }
    });

    //培训课订单
    public BindingCommand goRecord = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(TrainOrdersActivity.class);
        }
    });

    //我的优惠券
    public BindingCommand goMyCoupon= new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(MyCouponActivity.class);
        }
    });

    //我的客服
    public BindingCommand telKf= new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            getUC().getCallTel().setValue(callKfTel.get().getInfo().getTel());
        }
    });

    //设置页面
    public BindingCommand goSetting= new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(SettingActivity.class);
        }
    });


    @Override
    protected void returnData(int code, Object dataBean) {
        super.returnData(code, dataBean);

        if(code == Constants.GET_MEMBER_INDEX_INFO){
            PersonBean.InfoBean infoBean = ((PersonBean)dataBean).getInfo();
            entity.set(infoBean);

            //获取客服电话
            clearParams().setParams("type","pt");
            requestData(Constants.GET_ONLINE_KF);
        }

        if(code == Constants.GET_ONLINE_KF){
            KeFuBean keFuBean = (KeFuBean)dataBean;
            callKfTel.set(keFuBean);
        }
    }


}
